<script setup lang="ts">
import { ref } from "vue";
import { useRole } from "./utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

import Refresh from "~icons/ep/refresh";
import Checkbox from "~icons/ri/checkbox-fill";
import Lock from "~icons/ri/lock-2-line";

defineOptions({
  name: "groupcallTaskCustomerStatement"
});

const formRef = ref();
const {
  permissions,

  shortcuts,
  form,
  loading,
  columns,
  dataList,
  pagination,
  tableRef,
  multipleSelection,
  taskList,

  addClick,

  onSearch,
  resetForm,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleSelectionClear
} = useRole();

const tabChange = e => {
  dataList.value = [];
  pagination.currentPage = 1;
  if (e == "autoOutboundCall") {
    columns.unshift({
      type: "selection",
      align: "left"
    });
  } else {
    if (columns[0].align && columns[0].align == "left") {
      columns.shift();
    }
  }
  onSearch();
};
</script>

<template>
  <div>
    
    <div class="main">
      <el-form
        ref="formRef"
        :inline="true"
        :model="form"
        class="search-form bg-bg_color w-full pl-8 pt-[12px] overflow-auto"
      >
        <!-- <el-form-item prop="project">
        <el-select
          v-model="form.project"
          placeholder="群呼项目"
          clearable
          class="w-[120px]!"
        >
          <el-option label="群呼" value="群呼" />
        </el-select>
      </el-form-item> -->
        <!-- <el-form-item
          label="拨打时间"
          prop="time"
          v-if="permissions.is_search_createAt"
        >
          <el-date-picker
            v-model="form.rangeTime"
            type="daterange"
            class="w-[240px]!"
            unlink-panels
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            :shortcuts="shortcuts"
            value-format="X"
          />
        </el-form-item> -->
        <!-- <el-form-item prop="status" v-if="permissions.is_search_intension">
          <el-select
            v-model="form.status"
            placeholder="客户状态"
            clearable
            class="w-[120px]!"
          >
            <el-option label="接通未确定" value="unkown" />
            <el-option label="无意向" value="refuse" />
            <el-option label="有意向" value="intend" />
          </el-select>
        </el-form-item>
        <el-form-item prop="status" v-if="permissions.is_search_gain">
          <el-select
            v-model="form.isGain"
            placeholder="领取状态"
            clearable
            class="w-[120px]!"
          >
            <el-option label="未领取" :value="0" />
            <el-option label="已领取" :value="1" />
          </el-select>
        </el-form-item> -->
        <el-form-item prop="phone" v-if="permissions.is_search_phone">
          <el-input
            type="number"
            v-model="form.phone"
            placeholder="电话号码"
            clearable
            class="w-[260px]!"
          />
        </el-form-item>
        <!-- <el-form-item prop="duration">
        <el-input
          type="number"
          v-model="form.duration"
          placeholder="时长超过"
          clearable
          class="w-[260px]!"
        ><template #append>秒钟</template></el-input>
      </el-form-item> -->

        <el-form-item>
          <el-button
            type="primary"
            :icon="useRenderIcon('ri/search-line')"
            :loading="loading"
            @click="onSearch"
          >
            查询
          </el-button>
          <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
            重置
          </el-button>
        </el-form-item>
      </el-form>

      <PureTableBar
        title=""
        :columns="columns"
        @refresh="onSearch"
        :key="columns.length"
      >
        <template v-slot="{ size, dynamicColumns }">
          <!-- 多选显示 -->
          <div class="multipleInner" v-if="multipleSelection.length">
            <IconifyIconOffline
              :icon="Checkbox"
              style="color: #fff; width: 18px; height: 18px; cursor: pointer"
              @click="handleSelectionClear"
            />
            <b>已选中 {{ multipleSelection.length }} 项</b>

            <div
              class="multipHandle"
              @click="addClick"
              v-if="permissions.is_callOrder_gain"
            >
              <IconifyIconOffline :icon="Lock" />
              <p>添加到我的领取客户</p>
            </div>
          </div>
          <pure-table
            ref="tableRef"
            align-whole="center"
            showOverflowTooltip
            table-layout="auto"
            :loading="loading"
            :size="size"
            adaptive
            :adaptiveConfig="{ offsetBottom: 108 }"
            :data="dataList"
            :columns="dynamicColumns"
            :pagination="{ ...pagination, size }"
            :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }"
            @selection-change="handleSelectionChange"
            @page-size-change="handleSizeChange"
            @page-current-change="handleCurrentChange"
          >
          <template #record="{ row }">
          <audio controls v-if="row.record" style="width: 180px;height: 30px;">
            <source :src="row.record">
          </audio>
        </template>
          </pure-table>
        </template>
      </PureTableBar>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.cardTab {
  margin: 0 !important;
  padding: 16px;
  background-color: #fff;
}
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

:deep(.el-form--inline .el-form-item) {
  margin-right: 12px;
}

.multipleInner {
  background-color: var(--pure-theme-menu-active-before);
  height: 45px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 14px;
  color: #ffffff;

  b {
    margin-left: 3px;
  }

  .multipHandle {
    padding: 5px 8px;
    margin-left: 30px;
    display: flex;
    align-items: start;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.1s;

    svg {
      font-size: 16px;
      color: #ffffff;
      margin-top: 2px;
    }

    p {
      margin-left: 5px;
    }

    &:hover {
      background-color: #ffffff;
      color: #000000;

      :deep(svg) {
        color: #000000;
      }
    }
  }
}

.main {
  margin: 12px 12px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}

:deep(.handleButton) {
  margin-top: 30px;
}
</style>
